#include <stdio.h>
#include <memory.h>

/* For any odd number 1 <= k <= N, isprime[k/2] = 1 if k is prime. */
void sieve(unsigned char isprime[], int N)
{
    int p;
    memset(isprime, 1, (N+1)/2);
    isprime[0] = 0; /* 1 is not considered prime */
    for (p = 3; p*p <= N; p += 2)
    {
        if (isprime[p/2])
        {
            int k;
            for (k = p*p; k <= N; k += 2*p)
                isprime[k/2] = 0;
        }
    }
}

int count_primes_between(int A, int B)
{
    int i, count = (A <= 2 && B >= 2)? 1 : 0;
    unsigned char isprime[50000];

    if (B <= 1)
        return 0;
    if (A < 0)
        A = 0;

    sieve(isprime, B);
    for (i = A/2; i <= (B-1)/2; i++)
        count += isprime[i];
    return count;
}

int main()
{
    int A, B;
    while (scanf("%d %d", &A, &B) && !(A == -1 && B == -1))
    {
        printf("%d\n", count_primes_between(A,B));
    }
    return 0;
}
